package offer;

public class offerII_0054 {
    public TreeNode convertBST(TreeNode root) {
        int[] sum=new int[1];
        sum[0]=0;
        replace(root,sum);
        return root;
    }
    public void replace(TreeNode node,int[] sum){
        if(node==null) return;
        replace(node.right,sum);
        sum[0]+=node.val;
        node.val=sum[0];
        replace(node.left,sum);
    }
}
